<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<link rel="stylesheet" type="text/css" href="../../../Themes/default/easyui.css">
		<link rel="stylesheet" type="text/css" href="../../../Themes/icon.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/demo.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/common.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/ystep.css">
		<script type="text/javascript" src="../../../JS/jquery.min.js"></script>
		<script type="text/javascript" src="../../../JS/jquery.easyui.min.js"></script>
		<script type="text/javascript" src="../../../JS/common.js"></script>
		<script type="text/javascript" src='../../../JS/SHA-1.js'></script>
		<script type="text/javascript" src="../../../JS/ystep.js"></script>
		<script type="text/javascript" src="../../../JS/LogisticsShareFunction/SearchShareFunction.js"></script>
		<style type="text/css">
			#flowchat {
				margin-left: 35%;
				padding-top: 40px;
			}
		</style>
	</head>

	<body style="padding: 0px;">
		<div class="easyui-layout" style="width:100%;height:550px;">
			<div id="div_search" data-options="region:'north'" style="height:90px;">

			</div>
			<div data-options="region:'center'">
				<div class="easyui-layout" style="width: 100%;height:459px">
					<div data-options="region:'north'" style="overflow:hidden">
						<div id="STATE_Panel" class="easyui-panel" title="订单状态" style="height: 170px;">
							<div class="ystep4" id="flowchat"></div>
						</div>
					</div>
					<div data-options="region:'center'">
						<div class="easyui-panel" title="订单列表" style="width: 100%;height: 288px;">
							<div>
								<table id="dg" class="table_style" data-options="checkbox:true" style="width: 100%;">
								</table>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div id="toolbar"></div>
	</body>
	<script>
		var gOrderStep = {};
		CreateEnum();
		var saleid;
		var deliverid;
		var purchaseid;
		var purchasedate;
		var orderid;

		var content = "";
		content = AddToolBar(TOOLBAR_REDO);
		$("#toolbar").append(content);

		var searchType = SEARCH_DISTRIBUTION_DATE_START+SEARCH_DISTRIBUTION_DATE_END;
		searchType += SEARCH_CUSTOMER_TYPE + SEARCH_CUSTOMER_NAME+SEARCH_STATE;
		var content = buildSearchOptions(searchType, "");
		$("#div_search").append(content);

		function doSearch() {
			var searchCondition = "";
			searchCondition = processSearchCondition();
			var _url = RemoteLinkAddress + '/logistics/salesorder/list.do?' + searchCondition;
			$('#dg').datagrid('options').url = _url;
			$('#dg').datagrid('reload');
		}

		function CreateEnum() {　　　　　　　　　　　
			gOrderStep.ACCEPT_ORDER = 1;　　　　　　　　　　　
			gOrderStep.PURCHASE = 2;　　　　　　　　　　　
			gOrderStep.WAREHOUSE_IN = 3;　　　　　　　　　　　
			gOrderStep.WAREHOUSE_OUT = 4;　　　　　　　　　　　
			gOrderStep.DELIVERY = 5;
		}
		var stepData = [{
			title: "订单",
			content: "公司已接单",
			url: "",
		}, {
			title: "采购",
			content: "该订单还未采购",
			url: "",
		}, {
			title: "出库",
			content: "该订单还未出库",
			url: "",
		}, {
			title: "配送",
			content: "该订单还未配送",
			url: "",
		}, {
			title: "结算",
			content: "该订单还未结算",
			url: "",
		}];

		function redodata() {
			checkAllData("/logistics/salesorder/list.do");
		}

		$('#dg').datagrid({
			url: RemoteLinkAddress + '/logistics/salesorder/list.do',
			method: 'get',
			toolbar: '#toolbar',
			pagination: 'true',
			rownumbers: 'true',
			autoRowHeight: 'true',
			fitColumns: 'true',
			singleSelect: 'true',
			height: 259,
			/*表格中的列名以及各自列名的ID*/
			columns: [
				[{
					field: 'ID',
					title: 'ID',
					width: '4%',
					align: 'center'
				}, {
					field: 'CUSTOMER_TYPE',
					title: '用户组',
					width: '20%',
					align: 'center'
				}, {
					field: 'CUSTOMER_NAME',
					title: '配送单位名称',
					width: '20%',
					align: 'center'
				}, {
					field: 'DISTRIBUTION_DATE',
					title: '配送时间',
					width: '10%',
					align: 'center'
				}, 
				{
					field: 'STATE',
					title: '订单状态',
					width: '10%',
					align: 'center'
				},{
					field: 'CREATE_TIME',
					title: '建单时间',
					width: '19%',
					align: 'center'
				}, {
					field: "CREATE_MEN",
					title: '建单人',
					width: '10%',
					align: 'center'
				}]
			],
			onClickRow: function(index, row) {
				createDisplayArea();
				stepData = initialStepDataArr(stepData);
				getSalesData(row.ID);
				getPurchaseData(row.STATE);
				getWarehouseOut(row.ID);
				getDeliverData(row.ID);
				GetStepData();
				SetStep(row.STATE);
			}
		});

		function createDisplayArea() {
			var content = "<div class='ystep4' id='flowchat'></div>";
			if($("#flowchat")) {
				$("#flowchat").remove();
			}
			$("#STATE_Panel").append(content);
		}

		function GetStepData() { //步骤数据的大小，颜色
			$(".ystep4").loadStep({
				size: "large",
				color: "blue",
				steps: stepData
			});
		}

		function SetStep(_step) {
			var _stepNum = 1;
			switch(_step) {
				case "下单":
					_stepNum = 1;
					break;
				case "采购完成":
					_stepNum = 2;
					break;
				case "入库完成":
					_stepNum = 3;
					break;
				case "出库完成":
					_stepNum = 4;
					break;
				case "结算完成":
					_stepNum = 5;
					break;

			}
			$(".ystep4").setStep(_stepNum);
		}

		function getSalesData(_orderid) { //统一获取远程的数据
			var pLocation = "UI/LOGISTICS/SellOrder/SellOrderAdd.html?id=" + _orderid;
			stepData[0].url = "AddTabIn(\"销售单详情\", parent.$(\"#tabs\"), '" + pLocation + "')";
			stepData[0].content = "销售单号" + _orderid;
		}

		function getPurchaseData(STATE) {
			if(STATE == "下单") {
				return;
			}
			stepData[1].content = "采购完毕";
			//			$.ajax({ //调用ajax方法，从服务器获取到该订单的所有数据
			//				type: "get",
			//				url: RemoteLinkAddress + "/logistics/salesorder/findwhobysales.do?ID=" + _orderid,
			//				async: false,
			//				dataType: "json", //服务器返回的数据类型
			//				success: function(result) {
			//					console.log(result);
			//					if(result != null && result.length != 0) {
			//						stepData[1].content = "正在采购中";
			//					}
			//
			//				}, //请求成功后，接受服务器传来的Json字符串，并做相应的处理
			//				error: function(xhr, status, error) {
			//					$.messager.alert("错误", "getSalesData请求失败!");
			//				}
			//			});
			if(STATE == "结算完成"){
				stepData[4].content = "该订单已结算";
			}
		}

		function getWarehouseOut(_orderid) {
			$.ajax({ //调用ajax方法，从服务器获取到该订单的所有数据
				type: "get",
				url: RemoteLinkAddress + "/logistics/salesorder/findwhobysales.do?ID=" + _orderid,
				dataType: "json", //服务器返回的数据类型
				async: false,
				success: function(result) {
					if(result != null && result.length != 0) {
						var id = result[0].ID;
						console.log(id);
						var pLocation = "UI/LOGISTICS/WareHouseOutOrder/WareHouseOutOrderAdd.html?id=" + id;
						stepData[2].url = "AddTabIn(\"出库单详情\", parent.$(\"#tabs\"), '" + pLocation + "')";
						stepData[2].content = "出库单号" + id;
					}
				}, //请求成功后，接受服务器传来的Json字符串，并做相应的处理
				error: function(xhr, status, error) {
					$.messager.alert("错误", "getSalesData请求失败!");
				}
			});
		}

		function getDeliverData(_orderid) //统一获取远程的数据（发送数据）
		{
			$.ajax({ //调用ajax方法，从服务器获取到该订单的所有数据
				type: "get",
				url: RemoteLinkAddress + "/logistics/salesorder/finddelbysales.do?ID=" + _orderid,
				dataType: "json", //服务器返回的数据类型
				async: false,
				success: function(result) {
					if(result != null && result.length != 0) {
						var id = result[0].ID;
						console.log(id);
						var pLocation = "UI/LOGISTICS/DeliverManagementOrder/DeliverManagementOderModi.html?id=" + id;
						stepData[3].url = "AddTabIn(\"配送单详情\", parent.$(\"#tabs\"), '" + pLocation + "')";
						stepData[3].content = "配送号" + id;
					} else {
						//						createDisplayArea();
						//						GetStepData();
						$(".ystep4").setStep(3);
					}
				}, //请求成功后，接受服务器传来的Json字符串，并做相应的处理
				error: function(xhr, status, error) {
					$.messager.alert("错误", "getSalesData请求失败!");
				}
			});
		}

		function initialStepDataArr(stepData) {
			var arr = [{
				title: "订单",
				content: "公司已接单",
				url: "",
			}, {
				title: "采购",
				content: "该订单还未采购",
				url: "",
			}, {
				title: "出库",
				content: "该订单还未出库",
				url: "",
			}, {
				title: "配送",
				content: "该订单还未配送",
				url: "",
			}, {
				title: "结算",
				content: "该订单还未结算",
				url: "",
			}];
			return arr;
		}
	</script>

</html>